package com.ws.springboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ws.springboot.common.Result;
import com.ws.springboot.entity.Bookinfor;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;


import com.ws.springboot.service.ISysRoleService;
import com.ws.springboot.entity.SysRole;


import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2022-06-10
 */
        @RestController
        @RequestMapping("//role")
            public class SysRoleController {
    
    @Resource
    private ISysRoleService sysRoleService;

    @PostMapping
    public Result save(@RequestBody SysRole sysRole) {
            return Result.success(sysRoleService.saveOrUpdate(sysRole));
            }


    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
            return Result.success(sysRoleService.removeById(id));
            }


    @GetMapping
    public Result findAll() {
            return Result.success(sysRoleService.list());
            }

    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
            return Result.success(sysRoleService.getById(id));
            }

    @PostMapping("del/batch")
    public Boolean deleteBatch(@RequestBody List<Integer> ids){
            return sysRoleService.removeBatchByIds(ids);
            }

    @GetMapping("/page")
    public IPage<SysRole> findPage(@RequestParam Integer pageNum,
                                     @RequestParam Integer pageSize,
                                  @RequestParam(defaultValue = "") String name){
//                                    @RequestParam(defaultValue = "") String email,
//                                    @RequestParam(defaultValue = "") String address){
            QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
            if(!"".equals(name)){
            queryWrapper.like("name" ,name);
            }
//            if(!"".equals(email)){
//            queryWrapper.like("nickname",email);
//            }
//            if(!"".equals(address)){
//            queryWrapper.like("address",address);
//            }

//                queryWrapper.orderByDesc("id");
            return sysRoleService.page(new Page<>(pageNum, pageSize), queryWrapper);
            }





    }

